class Solution {
public:
    bool check(long long int  mid,long long int x)
    {
        if(mid*mid<=x) return true;
        return false;
    }
    int mySqrt(int x) {
        int left=0,right=x,ans=-1;
        while(left<=right)
        {
            int mid=(right-left)/2+left;
            if(check(mid,x))
            {
                ans=mid;
                left=mid+1;
            }
            else
            {
                right=mid-1;
            }
        }
        return ans;
    }
};